package com.wn.test;

import com.wn.bean.Person;
import com.wn.bean.Student;
import com.wn.bean.User;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.Date;

/**
 * @author yellow Docter
 * @date 2022 -07-06
 * @desc
 */
public class SpringTest2 {


    private ApplicationContext applicationContext = null;

    @Before
    public void init() {
        applicationContext = new ClassPathXmlApplicationContext("applicationContext2.xml");
    }

    @Test
    public void demo01() {

        Person p1 = applicationContext.getBean("p1", Person.class);
        System.out.println("p1 = " + p1);

    }

    @Test
    public void demo02() {

        Person p2 = applicationContext.getBean("p2", Person.class);
        System.out.println("p2 = " + p2);

    }


    @Test
    public void demo03() {

        Person p3 = applicationContext.getBean("p3", Person.class);
        System.out.println("p3 = " + p3);

    }

    @Test
    public void demo04() {

        Person p4 = applicationContext.getBean("p4", Person.class);
        System.out.println("p4 = " + p4);

    }

    /**
     * 测试 scope 配置
     *  <bean id="user" class="com.wn.bean.User" scope="singleton"> 单例
     *  <bean id="user" class="com.wn.bean.User" scope="prototype"> 每次获取对象 都是一个新的对象
     *
     *  配置的时候 不能和 lombok一起使用 (默认是单例)
     *
     */
    @Test
    public void demo05(){

        User user1 = applicationContext.getBean("user", User.class);
        System.out.println("user1 = " + user1);

        User user2 = applicationContext.getBean("user", User.class);
        System.out.println("user2 = " + user2);

    }

}
